package megrez.job.custom.web.vo;

import java.util.Date;

import org.springframework.beans.BeanUtils;

import lombok.Getter;
import lombok.Setter;
import megrez.job.custom.domain.Config;
import megrez.job.custom.domain.Log;
import megrez.job.custom.domain.TaskState;

/**
 * 日志
 * 
 * @author Lucky Yang
 * @since 2.6.9
 */
@Getter
@Setter
public class LogVO {
    private String id;
    private Integer version;
    private Date createdDate;
    private String configSnapshot;
    private TaskState state;
    private String message;
    private Long costTime;

    private String configId;
    private String className;
    private String methodName;
    private String methodParams;
    private String cronExpression;

    public static LogVO of(Log log) {
        if (log == null) {
            return null;
        }
        LogVO rslt = new LogVO();
        BeanUtils.copyProperties(log, rslt);

        Config config = log.getConfig();
        if (config != null) {
        rslt.setConfigId(config.getId());
        rslt.setClassName(config.getClassName());
        rslt.setMethodName(config.getMethodName());
        rslt.setMethodParams(config.getMethodParams());
        rslt.setCronExpression(config.getCronExpression());
        }
        return rslt;
    }

    @Override
    public boolean equals(Object o) {
        return super.equals(o);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }   
}
